//
//  QBWTVC.m
//  SanYiTeaching
//
//  Created by 李文强 on 2019/4/18.
//  Copyright © 2019 SanYi. All rights reserved.
//

#import "QBWTVC.h"
#import "WTFDRightTableView.h"


@interface QBWTVC () {
    NSString *_banji;//班级id
    
}

@property (nonatomic, strong) SYNoLabel *noLab;
@property (nonatomic, strong) NSMutableArray *dataListArr;
@property (nonatomic, strong) UIView *lineView;
@property (nonatomic, strong) WTFDRightTableView *rightList1;

@end

@implementation QBWTVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self initSubView];
}
- (void)initSubView{
    self.view.backgroundColor = [UIColor whiteColor];
    _headerSearchView = [[WTFDSearchView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width/2-50, 50)];
    _headerSearchView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:self.headerSearchView];
    [_headerSearchView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@0);
        make.right.equalTo(self.view.mas_centerX).offset(-50);
        make.top.equalTo(@0);
        make.height.equalTo(@44);
    }];
    
    [self.view addSubview:self.leftTableList.view];
    [_leftTableList.view mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@0);
        make.right.equalTo(self.view.mas_centerX).offset(-50);
        make.top.equalTo(@44);
        make.bottom.equalTo(@0);
    }];
    
    _lineView = [[UIView alloc]init];
    _lineView.backgroundColor = LINCOLOR;
    [self.view addSubview:_lineView];
    _lineView.hidden = YES;
    [_lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.leftTableList.view.mas_right);
        make.width.equalTo(@1);
        make.top.equalTo(self.leftTableList.view.mas_top);
        make.bottom.equalTo(@0);
    }];
    
    [self.view addSubview:self.rightList.view];
    [_rightList.view mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.lineView.mas_right);
        make.top.equalTo(self.leftTableList.view.mas_top);
        make.right.equalTo(@0);
        make.bottom.equalTo(@0);
    }];
    [self.view addSubview:self.rightList1.view];
    [_rightList1.view mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.lineView.mas_right);
        make.top.equalTo(self.leftTableList.view.mas_top);
        make.right.equalTo(@0);
        make.bottom.equalTo(@0);
    }];
    
    
    _noLab = [[SYNoLabel alloc] initWithNameStr:@"" contView:self.view];
    _dataListArr = [NSMutableArray array];
    
    __weak typeof(self) weakSelf = self;
    //分组
    self.leftTableList.block = ^(NSString * _Nonnull sortid) {
        [weakSelf requestRightSortId:sortid];
    };
    //学生
    self.leftTableList.xsBlock = ^(NSString * _Nonnull sortid) {
        [weakSelf requestRightMeiFenZu:sortid];
    };
    
    self.leftTableList.wtBlock = ^(NSInteger index) {
        
    };
    
}


- (void)requestDataBanJi:(NSString *)banji keyStr:(NSString *)keyStr {
    if (banji.length == 0) {
        banji = @"0";
    }
    __weak typeof(self) weakSelf = self;
    [self.dataListArr removeAllObjects];
    [MBProgressHUD mj_showMessage:nil toView:self.view];
    [SYRequestAPI fd_requestFenZuQuestionSortKeyWord:@"" success:^(NSMutableArray *listArr) {
        [MBProgressHUD mj_hideHUDForView:self.view];
        [weakSelf.dataListArr addObject:listArr];
        
        if (listArr.count > 0) {
            SYWenTiFenZuModel *wtfz = listArr.firstObject;
            [weakSelf requestRightSortId:wtfz.sortId];
        }
        
        
        //请求全部问题
        [SYRequestAPI fd_requestTutorQuestionTutorServiceIsAnswer:@"-1" keyword:@"" classId:banji pageIndex:0 pageSize:1000 success:^(NSMutableArray *listArr) {
            if (listArr.count == 0) {
                weakSelf.noLab.hidden = YES;
            }
            [weakSelf.dataListArr addObject:listArr];
            [weakSelf.leftTableList chuanRuShuJuShuXinViewData:weakSelf.dataListArr];
        } fail:^(NSError *error) {
            
        }];
    } fail:^(NSError *error) {
        [MBProgressHUD mj_hideHUDForView:self.view];
        self.leftTableList.view.hidden = YES;
        self.headerSearchView.hidden = YES;
        self.rightList.view.hidden = YES;
        self.lineView.hidden = YES;
        weakSelf.noLab.hidden = NO;
    }];
    
}
//右边数据请求
- (void)requestRightSortId:(NSString *)sortId {
    __weak typeof(self) weakSelf = self;
    [MBProgressHUD mj_showLoading];
    [SYRequestAPI fd_requestFenZuQuestionSortListSortId:sortId keyWord:@"" pageIndex:0 pageSize:1000 success:^(NSMutableArray *listArr) {
        [MBProgressHUD mj_hideHUD];
        weakSelf.rightList.view.hidden = NO;
        weakSelf.rightList1.view.hidden = YES;
        [weakSelf.rightList requestDataListArr:listArr];
    } fail:^(NSError *error) {
        [MBProgressHUD mj_hideHUD];
        [weakSelf.rightList requestDataListArr:[NSMutableArray array]];
    }];
}
//学生问题id
- (void)requestRightMeiFenZu:(NSString *)xsid {
    __weak typeof(self) weakSelf = self;
    [SYRequestAPI fd_requestQuestionDetailQuestionId:xsid success:^(NSMutableArray *listArr) {
        
        weakSelf.rightList.view.hidden = YES;
        weakSelf.rightList1.view.hidden = NO;
        [weakSelf.rightList1 requestDataArr:listArr];
        
    } fail:^(NSError *error) {
        [weakSelf.rightList1 requestDataArr:[NSMutableArray array]];
    }];
}



- (QBWTLeftViewList *)leftTableList{
    if (!_leftTableList) {
        QBWTLeftViewList *view = [[QBWTLeftViewList alloc]init];
        view.fenZuGuanLiBlock = ^{
            [self->_mainDelegate guanLiFenZuClick];
        };
        _leftTableList = view;
    }
    return _leftTableList;
}
- (QBWTRightList *)rightList{
    if (!_rightList) {
        QBWTRightList *view = [[QBWTRightList alloc]init];
        _rightList = view;
    }
    return _rightList;
}
- (WTFDRightTableView *)rightList1{
    if (!_rightList1) {
        WTFDRightTableView *view = [[WTFDRightTableView alloc]init];
        _rightList1 = view;
        _rightList1.view.hidden = YES;
    }
    return _rightList1;
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
